 /*
  * Mango CMS
  * Copyright 2008, Mango Web, and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
package org.mangocms.admin.model.messaging;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
import org.mangocms.model.user.User;

/**
 * A Message sent between two users in the Mango administration
 * 
 * @author <a href="tanordheim@gmail.com">Trond Arve Nordheim</a>
 * @version $Revision: 1.1 $
 */
@Entity
@Table(name = "mango_admin_messages")
public class Message implements Serializable {

	private static final long serialVersionUID = 1L;

	@Column(name = "id")
	@Id @GeneratedValue
	private Integer id;
	
	@Column(name = "subject")
	@Length(max = 255)
	@NotNull
	private String subject;
	
	@Lob
	@NotNull
	private String body;

	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "autor_id", referencedColumnName = "id")
	@NotNull
	private User author;
	
	@Column(name = "sent_time")
	@NotNull
	private Date sentTime;

	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "recipient_id", referencedColumnName = "id")
	@NotNull
	private User recipient;
	
	@Column(name = "is_read")
	private Boolean read = false;
	
	@Column(name = "read_time")
	private Date readTime;
	
	/**
	 * Create a new Message.
	 */
	public Message() {
	}

	/**
	 * Get the id.
	 * 
	 * @return the id.
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * Set the id.
	 * 
	 * @param id The id to set.
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * Get the subject.
	 * 
	 * @return the subject.
	 */
	public String getSubject() {
		return subject;
	}

	/**
	 * Set the subject.
	 * 
	 * @param subject The subject to set.
	 */
	public void setSubject(String subject) {
		this.subject = subject;
	}

	/**
	 * Get the body.
	 * 
	 * @return the body.
	 */
	public String getBody() {
		return body;
	}

	/**
	 * Set the body.
	 * 
	 * @param body The body to set.
	 */
	public void setBody(String body) {
		this.body = body;
	}

	/**
	 * Get the author.
	 * 
	 * @return the author.
	 */
	public User getAuthor() {
		return author;
	}

	/**
	 * Set the author.
	 * 
	 * @param author The author to set.
	 */
	public void setAuthor(User author) {
		this.author = author;
	}

	/**
	 * Get the sentTime.
	 * 
	 * @return the sentTime.
	 */
	public Date getSentTime() {
		return sentTime;
	}

	/**
	 * Set the sentTime.
	 * 
	 * @param sentTime The sentTime to set.
	 */
	public void setSentTime(Date sentTime) {
		this.sentTime = sentTime;
	}

	/**
	 * Get the recipient.
	 * 
	 * @return the recipient.
	 */
	public User getRecipient() {
		return recipient;
	}

	/**
	 * Set the recipient.
	 * 
	 * @param recipient The recipient to set.
	 */
	public void setRecipient(User recipient) {
		this.recipient = recipient;
	}

	/**
	 * Get the read.
	 * 
	 * @return the read.
	 */
	public Boolean getRead() {
		return read;
	}

	/**
	 * Set the read.
	 * 
	 * @param read The read to set.
	 */
	public void setRead(Boolean read) {
		this.read = read;
	}

	/**
	 * Get the readTime.
	 * 
	 * @return the readTime.
	 */
	public Date getReadTime() {
		return readTime;
	}

	/**
	 * Set the readTime.
	 * 
	 * @param readTime The readTime to set.
	 */
	public void setReadTime(Date readTime) {
		this.readTime = readTime;
	}

}
